package com.liangzhong.manager
{
	import com.common.utils.HashMap;
	
	import flash.system.ApplicationDomain;
	/**
	 *资源管理 
	 * @author lxh
	 * 
	 */	
	public class ResourceManager implements IResourceManager
	{
		private static var _instance:ResourceManager = null;
		
		private var _resources :HashMap;
		
		public function ResourceManager()
		{
			_resources = new HashMap();
		}
		/**
		 * 
		 * @return 
		 * 
		 */		
		public static function get instance() : IResourceManager
		{
			if (_instance == null)
			{
				_instance = new ResourceManager;
			}
			return _instance;
		}
		/**
		 * 
		 * @param className
		 * @param domain
		 * @return 
		 * 
		 */		
		public function getClass(className:String, domain:ApplicationDomain=null):Class
		{
			var rstClass:Class;
			var name:* = className;
			var appDomain:* = domain;
			if (appDomain == null)
			{
				appDomain = ApplicationDomain.currentDomain;
			}
			try
			{
				rstClass = appDomain.getDefinition(name) as Class;
			}
			catch (err:Error)
			{
			}
			return rstClass;
		}
		/**
		 * 
		 * @param className
		 * @param domain
		 * @return 
		 * 
		 */		
		public function getClassInstance(className:String, domain:ApplicationDomain=null):Object
		{
			var classInstance:* = this.getClass(className, domain);
			if (classInstance != null)
			{
				return new classInstance();
			}
			return null;
		}
		/**
		 * 
		 * @param type
		 * @return 
		 * 
		 */		
		public function getString(type:int):String
		{
			return null;
		}
		/**
		 * 
		 * @param configName
		 * @return 
		 * 
		 */		
		public function getResource(key:*):*
		{
			return _resources.get(key);
		}
		
		public function isContainResource(key:*):Boolean
		{
			if(_resources.containsKey(key))
			{
				return true;
			}
			return false;
		}
		
		public function putResource(key:*, value:*):void
		{
			_resources.put(key,value);
		}
	}
}